*------------------------------------------------------------------------------
* run `PI_process_text_zip.R' to produce tess_zip_text.dta file
*==============================================================================
* zipcode analysis 
use "${dir_processed}/tess_zip_text.dta",clear
gen politics = (mean_politics>0) if ~missing(mean_politics)

xtmelogit politics || zip: if year == 2016
estat icc 

*------------------------------------------------------------------------------
* run `PI_figure_topic_multiple_choice.R' to produce tess_zip_text.dta file
*==============================================================================
use "${dir_processed}/tess2016_multiple_choice_zip.dta",clear
xtset zip 
gen varname = "" 
gen icc = .
gen icc_se = . 
gen icc_lci = . 
gen icc_uci = .

local n = 1
foreach X of varlist topic2_* topic_* topic1_* {
	replace varname = "`X'" in `n'	
	*local X topic2_bradpitt	
	if ("`X'"=="topic2_bradpitt" | "`X'"=="topic2_arnoldpalmer" | "`X'" =="topic1_genewilder"){
		xtmelogit `X' || zip:, reiterate(200) intp(100)
	}
	else {
		xtmelogit `X' || zip:, reiterate(200)
	}
	estat icc 

	replace icc = `r(icc2)' in `n'
	replace icc_se = `r(se2)' in `n'
	matrix icc_ci = r(ci2)
	local icc_lci =icc_ci[1,1]
	local icc_uci =icc_ci[1,2]
	replace icc_lci = `icc_lci' in `n'
	replace icc_uci = `icc_uci' in `n'
	local n = `n'+1		
}

outsheet varname icc* if varname != "" using "./tables/tess2016_icc_zipcode_multiple.csv", comma replace 

